<html xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout"
      xmlns="http://www.w3.org/1999/html" layout:decorator="base/layout.html">


    <!-- start: Content -->
    <div layout:fragment="content" class="main ">

        <div class="row">
            <div class="col-lg-12">
                <ol class="breadcrumb">
                    <li><i class="fa fa-home"></i><a th:href="@{../infoManage/indexTotal}">首页</a></li>

                    <li><i class="fa fa-indent"></i>添加企业信息</li>
                </ol>
            </div>
        </div>

        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h2><i class="fa fa-indent red"></i><strong>添加企业信息</strong></h2>
                    </div>
                    <div class="panel-body">
                        <form id="modularForm"  method="post" enctype="multipart/form-data" class="form-horizontal ">
                            <div class="form-group">
                                <label class="col-md-3 control-label" for="select">承办部门</label>
                                <div th:if="${session.userInfo.departmentid==11}" class="col-md-2">
                                    <select  id="selectDepartment" name="departmentid" class="form-control" size="1"
                                            type="isNotSelectNull">
                                    </select>
                                    <span class="help-block">请选择承办部门(必填)</span>
                                </div>
                                <div th:if="${session.userInfo.departmentid!=11}" class="col-md-2">
                                    <input id="workInfoId" type="hidden" name="departmentid" class="form-control"
                                           th:value="${session.userInfo.departmentid}" >
                                    <input type="text"  class="form-control"
                                           th:value="${session.userInfo.department.department}" readonly >
                                </div>
                            </div>



                            <div class="form-group">
                                <label class="col-md-3 control-label" for="select">合作单位性质</label>
                                <div class="col-md-2">
                                    <select id="selectUnitsNature" name="unitsnatureid" class="form-control" size="1" type="isNotSelectNull">

                                    </select>
                                    <span class="help-block">请选择合作单位性质(必填)</span>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-md-3 control-label" for="text-input">合作单位名称</label>
                                <div class="col-md-2">
                                    <input type="text" id="text-input" name="unitscooperativename" class="form-control" placeholder="合作单位名称" required>
                                    <span class="help-block">请输入合作单位名称(必填)</span>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-md-3 control-label" for="select">企业类型</label>
                                <div class="col-md-2">
                                    <select id="selectCooperativeType" name="cooperativetypeid" class="form-control" size="1" type="isNotSelectNull">

                                    </select>
                                    <span class="help-block">请选择企业类型(必填)</span>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-md-3 control-label" for="select">企业规模</label>
                                <div class="col-md-2">
                                    <select id="selectScaleInfo" name="scaleid" class="form-control" size="1" type="isNotSelectNull">

                                    </select>
                                    <span class="help-block">请选择企业规模(必填)</span>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-md-3 control-label" for="select">外资属性</label>
                                <div class="col-md-2">
                                    <select id="selectForeignProperty" name="foreignpropertyid" class="form-control" size="1" type="isNotSelectNull">

                                    </select>
                                    <span class="help-block">请选择外资属性(必填)</span>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-md-3 control-label" for="select">行政区属</label>
                                <div class="col-md-2">
                                    <select id="selectAdministrativeDistrict" name="administrativedistrictid" class="form-control" size="1" type="isNotSelectNull">

                                    </select>
                                    <span class="help-block">请选择行政区属(必填)</span>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-md-3 control-label" for="select">企业所在地</label>
                                <div class="col-md-2">
                                    <select id="selectEnterpriseLocation" name="enterpriselocationid" class="form-control" size="1" type="isNotSelectNull">

                                    </select>
                                    <span class="help-block">请选择企业所在地(必填)</span>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-md-3 control-label" for="text-input">企业联系人及联系方式</label>
                                <div class="col-md-2">
                                    <input type="text"  name="contactsname" class="form-control" placeholder="企业联系人及联系方式" required>
                                    <span class="help-block">请输入企业联系人及联系方式(必填)</span>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-md-3 control-label" for="select">是否签署合作协议</label>
                                <div class="col-md-2">
                                    <select  name="signagreement" class="form-control" size="1" type="isNotSelectNull">
                                        <option value="-1">请选择</option>
                                        <option value="1">是</option>
                                        <option value="2">否</option>
                                    </select>
                                    <span class="help-block">请选择是否签署合作协议(必填)</span>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-md-3 control-label" for="date01">协议签署时间</label>
                                <div class="col-md-4">
                                    <div class="input-group date col-sm-6">
                                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                        <input type="text" class="form-control date-picker" id="signagreement" name="signtime" readonly required>

                                    </div>
                                    <span class="help-block">请选择协议签署时间(必填)</span>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-md-3 control-label" for="date01">协议到期时间</label>
                                <div class="col-md-4">
                                    <div class="input-group date col-sm-6">
                                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                        <input type="text" class="form-control date-picker" id="expirationTime" name="expirationtime" readonly required>

                                    </div>
                                    <span class="help-block">请选择协议到期时间(必填)</span>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-md-3 control-label" for="select">项目分类</label>
                                <div class="col-md-2">
                                    <select id="selectProjectType" name="projecttypeid" class="form-control" size="1" type="isNotSelectNull">

                                    </select>
                                    <span class="help-block">请选择项目分类(必填)</span>
                                </div>
                            </div>

                            <div id="cooperativeContentDiv">
                                <div  class="form-group">
                                        <label class="col-md-3 control-label" for="text-input">合作内容</label>


                                        <div class="col-md-2">
                                            <select id="selectCooperativeContent" name="cooperativeContentRelList[0].cooperativecontentid" class="form-control" size="1" type="isNotSelectNull">

                                            </select>


                                            <span class="help-block">请选择合作内容(必填)</span>
                                        </div>
                                        <span class="col-md-1">
                                            <button type="button" class=" btn btn-sm btn-info" onclick="addCooperativeContent()" > 添加</button>
                                        </span>

                                </div>


                                <div class="form-group">

                                    <label class="col-md-3 control-label" for="text-input">合作内容主要简介</label>
                                    <div class="col-md-2">
                                        <input type="text" name="cooperativeContentRelList[0].briefintroduction" class="form-control" placeholder="合作内容主要简介" required>
                                        <span class="help-block">请输入合作内容主要简介(必填)</span>
                                    </div>
                                </div>

                            </div>



                            <div id="workprogress" class="form-group">
                                <label class="col-md-3 control-label" for="text-input">本月工作进展情况</label>
                                <div class="col-md-2">
                                    <input type="text"  name="workprogress" class="form-control" placeholder="本月工作进展情况" required>
                                    <span class="help-block">请输入本月工作进展情况(必填)</span>
                                </div>
                            </div>


                            <div class="form-group">
                                <label class="col-md-3 control-label" for="text-input">下一步工作计划</label>
                                <div class="col-md-2">
                                    <input type="text"  name="workplan" class="form-control" placeholder="下一步工作计划" required>
                                    <span class="help-block">请输入下一步工作计划(必填)</span>
                                </div>
                            </div>



                            <div class="form-group">
                                <label class="col-md-3 control-label" for="text-input">阶段性工作成果</label>
                                <div class="col-md-2">
                                    <input type="text"  name="workresult" class="form-control" placeholder="阶段性工作成果" required>
                                    <span class="help-block">请输入阶段性工作成果(必填)</span>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-md-3 control-label" for="text-input">部门联系人及联系方式</label>
                                <div class="col-md-2">
                                    <input type="text"  name="departmentContactName" class="form-control" placeholder="部门联系人及联系方式" required>
                                    <span class="help-block">请输入部门联系人及联系方式(必填)</span>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-md-3 control-label" for="select">是否加密合作协议</label>
                                <div class="col-md-2">
                                    <select  name="protocolencryption" class="form-control" size="1" type="isNotSelectNull">
                                        <option value="-1">请选择</option>
                                        <option value="1">是</option>
                                        <option value="0">否</option>
                                    </select>
                                    <span class="help-block">请选择是否加密合作协议(必填)</span>
                                </div>
                            </div>

                            <div id="agreementDiv" class="form-group">
                                <label class="col-md-3 control-label" for="file-multiple-input">合作协议</label>
                                <div class="col-md-2">
                                    <input type="file" id="file-multiple-input" name="agreementUpload" multiple>
                                </div>

                                <span class="col-md-1">
                                    <button type="button" class=" btn btn-sm btn-info" onclick="addAgreementUrl()" > 添加</button>
                                </span>
                            </div>


                            <div id="legalPersonCertificateDiv" class="form-group">
                                <label class="col-md-3 control-label" for="file-multiple-input">企业法人资质证</label>
                                <div class="col-md-2">
                                    <input type="file"  name="legalPersonCertificateUpload" multiple>
                                </div>


                            </div>

                            <div id="businessLicenseDiv" class="form-group">
                                <label class="col-md-3 control-label" for="file-multiple-input">企业营业执照</label>
                                <div class="col-md-2">
                                    <input type="file"  name="businessLicenseUpload" multiple>
                                </div>


                            </div>

                            <div id="qualificationsDiv">
                                <div  class="form-group">
                                    <label class="col-md-3 control-label" for="file-multiple-input">企业资质</label>
                                    <div class="col-md-2">
                                        <input type="file"  name="qualificationsList[0].qualificationsURLUpload" multiple>
                                    </div>

                                    <span class="col-md-1">
                                        <button type="button" class=" btn btn-sm btn-info" onclick="addQualifications()" > 添加</button>
                                    </span>



                                </div>

                                <div class="form-group">

                                    <label class="col-md-3 control-label" for="text-input">企业资质名称</label>
                                    <div class="col-md-2">
                                        <input type="text" name="qualificationsList[0].qualificationsname" class="form-control" placeholder="企业资质名称">
                                        <span class="help-block">请输入企业资质名称</span>
                                    </div>
                                </div>

                            </div>







                            <div id="remarkDiv" class="form-group">
                                <label class="col-md-3 control-label" for="text-input">备注</label>
                                <div class="col-md-2">
                                    <input type="text"  name="remark" class="form-control" placeholder="备注">
                                    <span class="help-block">相关需求、建议等</span>
                                </div>
                            </div>




                            <br>

                    </div>
                    <div class="panel-footer">
                        <button id="submitBtn" type="submit" class="btn btn-sm btn-success"><i class="fa fa-dot-circle-o"></i> 提交</button>
                        <button type="reset" class="btn btn-sm btn-danger"><i class="fa fa-ban"></i>重置</button>
                    </div>
                    </form>
                </div>
            </div>


        </div><!--/.row-->


        <script>

            $(document).ready(function() {

                //加载承办部门
                initDepartment();

                //加载行政区属
                initAdministrativeDistrict();
                //加载企业所在地
                initEnterpriseLocation();

                //加载合作单位性质
                initUnitsNature();

                //加载企业类型
                initCooperativeType();

                //加载企业规模
                initScale();

                //加载外资属性
                initForeignProperty();

                //加载时间控件
                setDatePicker("#signagreement");

                //加载时间控件
                setDatePicker("#expirationTime");

                //加载项目分类
                initProjectType();


                //加载合作内容
                initCooperativeContent();
            })


            var qualificationsNum=0;
            //添加企业资质
            function addQualifications() {
                qualificationsNum+=1;
                var addItem = $('#qualificationsDiv').clone(true);
                $(addItem).find("button").html("删除").attr("onclick","javascript:$(this.parentNode.parentNode.parentNode).remove();");

                $(addItem).find("input[type='file']").val("");
                $(addItem).find("input[type='file']").attr("name","qualificationsList["+qualificationsNum+"].qualificationsURLUpload");

                $(addItem).find("input[type='text']").val("");
                $(addItem).find("input[type='text']").attr("name","qualificationsList["+qualificationsNum+"].qualificationsname");


                $('#remarkDiv').before(addItem);
            }

            //添加合作协议按钮
            function  addAgreementUrl() {
                var addItem = $('#agreementDiv').clone(true);
                $(addItem).find("button").html("删除").attr("onclick","javascript:$(this.parentNode.parentNode).remove();");
                $(addItem).find("input").val("");
                $('#legalPersonCertificateDiv').before(addItem);
            }

            //合作内容个数计数
            var num=0;

            //添加合作内容按钮
            function addCooperativeContent() {
                num+=1;
                var addItem = $('#cooperativeContentDiv').clone(true);
                $(addItem).find("button").html("删除").attr("onclick","javascript:$(this.parentNode.parentNode.parentNode).remove();");
                $(addItem).find("select").attr("name","cooperativeContentRelList["+num+"].cooperativecontentid");
                $(addItem).find("input").attr("name","cooperativeContentRelList["+num+"].briefintroduction");
                $(addItem).find("input").val("");
                $('#workprogress').before(addItem);
            }



            //加载承办部门
            function initDepartment(){
                $("#selectDepartment").append("<option value=-1>请选择</option>");
                $.ajax({
                    url:'../department/selectDepartmentInfo',
                    type:'get',
                    dataType:'json',
                    data:{},
                    success:function (data) {
                        for(var i in data){
                            $("#selectDepartment").append("<option value="+data[i].id+">"+data[i].department+"</option>");
                        }
                    }
                })
            }

            //加载行政区属
            function initAdministrativeDistrict() {
                $("#selectAdministrativeDistrict").append("<option value=-1>请选择</option>");
                $.ajax({
                    url:'../administrativeDistrict/SelectAdministrativeDistrictInfo',
                    type:'get',
                    dataType:'json',
                    data:{},
                    success:function (data) {
                            for (var i in data ){
                                $("#selectAdministrativeDistrict").append("<option value=" + data[i].id + ">" + data[i].administrativedistrict + "</option>");
                            }
                    }
                })
            }

            //加载企业所在地
            function initEnterpriseLocation() {
                $("#selectEnterpriseLocation").append("<option value=-1>请选择</option>");
                $.ajax({
                    url:'../enterpriseLocation/SelectEnterpriseLocationInfo',
                    type:'get',
                    dataType:'json',
                    data:{},
                    success:function (data) {
                            for (var i in data ){
                                $("#selectEnterpriseLocation").append("<option value=" + data[i].id + ">" + data[i].enterpriselocation + "</option>");
                            }
                    }
                })
            }

            //加载合作单位性质
            function initUnitsNature(){
                $("#selectUnitsNature").append("<option value=-1>请选择</option>");
                $.ajax({
                    url:'../unitsNature/selectUnitsNatureInfo',
                    type:'get',
                    dataType:'json',
                    data:{},
                    success:function (data) {
                        for(var i in data){
                            $("#selectUnitsNature").append("<option value="+data[i].id+">"+data[i].name+"</option>");
                        }
                    }
                })

            }

            //加载企业类型
            function initCooperativeType(){
                $("#selectCooperativeType").append("<option value=-1>请选择</option>");
                $.ajax({
                    url:'../cooperativeType/selectCooperativeTypeInfo',
                    type:'get',
                    dataType:'json',
                    data:{},
                    success:function (data) {
                        for(var i in data){
                            $("#selectCooperativeType").append("<option value="+data[i].id+">"+data[i].type+"</option>");
                        }
                    }
                })

            }

            //加载企业规模
            function initScale(){
                $("#selectScaleInfo").append("<option value=-1>请选择</option>");
                $.ajax({
                    url:'../scale/selectScaleInfo',
                    type:'get',
                    dataType:'json',
                    data:{},
                    success:function (data) {
                        for(var i in data){
                            $("#selectScaleInfo").append("<option value="+data[i].id+">"+data[i].scale+"</option>");
                        }
                    }
                })

            }

            //加载外资属性
            function initForeignProperty(){
                $("#selectForeignProperty").append("<option value=-1>请选择</option>");
                $.ajax({
                    url:'../foreignProperty/selectForeignPropertyInfo',
                    type:'get',
                    dataType:'json',
                    data:{},
                    success:function (data) {
                        for(var i in data){

                            $("#selectForeignProperty").append("<option value="+data[i].id+">"+data[i].property+"</option>");
                        }
                    }
                })

            }

            //加载项目分类
            function initProjectType(){
                $("#selectProjectType").append("<option value=-1>请选择</option>");
                $.ajax({
                    url:'../projectType/selectProjectTypeInfo',
                    type:'get',
                    dataType:'json',
                    data:{},
                    success:function (data) {
                        for(var i in data){
                            $("#selectProjectType").append("<option value="+data[i].id+">"+data[i].projecttype+"</option>");
                        }
                    }
                })

            }

            //加载合作内容
            function initCooperativeContent(){
                $("#selectCooperativeContent").append("<option value=-1>请选择</option>");
                $.ajax({
                    url:'../cooperativeContent/selectCooperativeContentList',
                    type:'get',
                    dataType:'json',
                    data:{},
                    success:function (data) {
                        for(var i in data){
                            $("#selectCooperativeContent").append("<option value="+data[i].id+">"+data[i].content+"</option>");
                        }
                    }
                })

            }


            $("#modularForm").validate({

                submitHandler: function(form)
                {

                    $('#modularForm').ajaxSubmit(      //ajax方式提交表单
                        {
                            url: 'workInfoAdd',
                            type: 'post',
                            success: function (data) {

                                layer.msg("添加成功");
                                setTimeout(function () {
                                    window.location = ("queryWorkInfo")
                                },1500);
                            }
                            //clearForm: false,//禁止清楚表单
                            //resetForm: false //禁止重置表单
                        });





                }
            })










        </script>

    </div>




    <!-- end: Content -->

